#-------------------------------------------------------------------------------------------
# File:		wc.pm
# Author:	A.C. Verbeck
# Date:		October 9, 2013
# Version:	1
# Summary:	word count module
# Description:
#			This perl module works with the verbose flag to print status information
#			about the main script.
#
# $Id: wc.pm 243 2014-02-09 08:03:29Z ac.verbeck@gmail.com $
#-------------------------------------------------------------------------------------------
#	Copyright and Disclaimer Notice
#
#	Copyright (c) 2013-2014 A.C. Verbeck
#
#	This file is part of perl-base: AWK-like processing system
#
#	perl-base is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	perl-base is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with perl-base. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------------------
	package wc;

	use trace;
	use strict;
	use warnings;
	use Exporter;
	use vars qw($VERSION @ISA @EXPORT);

	$VERSION = '1.0.0';
	@ISA	= qw(Exporter);
	@EXPORT = qw(new init begin line_proc end);

#-------------------------------------------------------------------------------------------
#	local variables
#-------------------------------------------------------------------------------------------
	our ($file_in, $file_out);
	our ($ct_word, $ct_line, $ct_char);
	
#-------------------------------------------------------------------------------------------
# function: new -- create the object
# This subroutine takes no arguments
#
# Usage Example:
#   $proc->new();
#-------------------------------------------------------------------------------------------
sub new
{
	my ($type) = @_;															# Extract the variables
	my ($self) = {};															# Create the object hash
	bless($self, $type);														# Connect the object to the type
	trace("new function called");												# trace the new call
	return($self);																# Return the object
}

	
#-------------------------------------------------------------------------------------------
#	subroutines
#-------------------------------------------------------------------------------------------
sub init
{
	my $self = shift(@_);														# get the object pointer

	($file_in, $file_out) = @_;													# get the input and output files
	$ct_line = 0;																# clear line count
	$ct_word = 0;																# clear word count
	$ct_char = 0;																# clear character count
}

#-------------------------------------------------------------------------------------------
#	wc_begin
#	This function does the following:
#-------------------------------------------------------------------------------------------
sub begin
{
	trace("Begin: $file_in $file_out");
}

#-------------------------------------------------------------------------------------------
#	base_line_proc
#	This function does the following:
#-------------------------------------------------------------------------------------------
sub line_proc
{
	my ($self, $line) = @_;														# get the parameters

	$ct_line++;																	# bump the line count
	$ct_char += length($line);													# get the character count

	$line =~ s/^\s+//;															# remove space from the start of the string
	$line =~ s/\s+$//;															# remove space from the end of the string
	my (@wd_arr) = split(/\s+/, $line);											# split the line into words
	$ct_word += @wd_arr;														# get the word count
}

#-------------------------------------------------------------------------------------------
#	base_end
#	This function does the following:
#-------------------------------------------------------------------------------------------
sub end
{
	trace("End: $file_in $file_out");
	print "line: $ct_line\n";
	print "word: $ct_word\n";
	print "char: $ct_char\n";
}

#-------------------------------------------------------------------------------------------
#	return status for module load
#-------------------------------------------------------------------------------------------
	return 1;

#
# End: wc.pm
#
